package com.fixme4trade.security;

import java.io.IOException;
import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletResponse;

import com.fixme4trade.domain.User;

import br.gov.frameworkdemoiselle.security.SecurityContext;

@SessionScoped
@Named("sessionManagement")
public class SessionManagement implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Inject
	SecurityContext securityContext;
				
	public SessionManagement (){
		
	}
	
	public String getLoggedInUsername() {
		User user = (User)securityContext.getUser(); 
		if (user != null)
			return user.getUsername();
		return "";
	}	
	
	public void doLogoff() throws IOException {
		securityContext.logout();		
				
		//FacesContext.getCurrentInstance().getExternalContext().dispatch("/public/index.html");
		
		//FacesContext.getCurrentInstance().responseComplete();
		
		//return "/public/index.jsf";
	}
}
